package com.beagle.njddapp.weight.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.beagle.njddapp.R;
import com.beagle.njddapp.bean.owner.NjBean;
import com.beagle.njddapp.ui.adapter.NjListAdapter;
import com.beagle.njddapp.ui.adapter.inter.RecyclerViewItemClickLisenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-13 20:13
 */
public class NjListDIalog extends Dialog implements RecyclerViewItemClickLisenter<NjBean> {

    @BindView(R.id.recyclerview)
    RecyclerView recyclerView;
    private NjListAdapter  njListAdapter;
    private List<NjBean> njBeanList;
    private onNjDialogItemClickLisenter onNjDialogItemClickLisenter;

    public void setOnNjDialogItemClickLisenter(NjListDIalog.onNjDialogItemClickLisenter onNjDialogItemClickLisenter) {
        this.onNjDialogItemClickLisenter = onNjDialogItemClickLisenter;
    }

    public void setNjBeanList(List<NjBean> list) {
        njBeanList.clear();
        njBeanList.addAll(list);
        njListAdapter.notifyDataSetChanged();
    }

    public NjListDIalog(@NonNull Context context)
    {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_list);
        ButterKnife.bind(this);
        if (getWindow() != null) {
            //按空白处不能取消动画
            setCanceledOnTouchOutside(true);
            //设置window背景，默认的背景会有Padding值，不能全屏。当然不一定要是透明，你可以设置其他背景，替换默认的背景即可。
            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            //一定要在setContentView之后调用，否则无效
            getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            getWindow().setWindowAnimations(R.style.DialogAnim);
        }
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        njBeanList=new ArrayList<>();
        njListAdapter=new NjListAdapter(njBeanList,getContext());
        njListAdapter.setOnItemClickLisenter(this);
        recyclerView.setAdapter(njListAdapter);
    }
    @OnClick({R.id.container})
    public void onCLick(View view){
        switch (view.getId()){
            case R.id.container:
                dismiss();
                break;

        }
    }

    @Override
    public void onItemClickLisenter(NjBean njBean) {
        if (onNjDialogItemClickLisenter!=null){
            onNjDialogItemClickLisenter.onItemClick(njBean);
        }
        dismiss();
    }

    public interface onNjDialogItemClickLisenter{
        void onItemClick(NjBean njBean);
    }
}
